function listProductType() {
    $.ajax({
        url : base + "/product_type/query_all",
        dataType : "json",
        success : function(data) {
            var list_html = "";
            for (var i = 0; i < data.list.length; i++) {
                var type = data.list[i];
                var tmp = "<option value='" + type.typeId + "' >" + type.typeName + "</option>";
                list_html += tmp;
            }
            $("#productTypeId").html(list_html);
        }
    });
}

function getProduct(id) {
    $.ajax({
        url : base + "/product/query_full",
        data : {"id":id},
        dataType : "json",
        success : function(data) {
        	$("#productId").attr("value", data.productId);
        	$("#productName").attr("value", data.productName);
        	$("#productPrice").attr("value", data.money.amount);
        	$("#moneyId").attr("value", data.money.moneyId);
        	$("#productTypeId").attr("value", data.productTypeId);
        	$("#productTypeId").val(data.productTypeId);
        }
    });
}

function addProduct() {
	$.ajax({
        url : base + "/product/add",
        data : $("#add_product_form").serialize(),
        dataType : "json",
        success : function(data) {
        	if(data.ok) {
        		alert("新增成功");
        		location = document.referrer;
        	} else {
        		alert(data.msg);
        	}
        }
    });
}

function updateProduct() {
    $.ajax({
        url : base + "/product/update",
        data : $("#add_product_form").serialize(),
        dataType : "json",
        success : function(data) {
        	if(data.ok) {
        		alert("修改成功");
        		location = document.referrer;
        	} else {
        		alert(data.msg);
        	}
        }
    });
}

function getRequest() {   
   var url = location.search; //获取url中"?"符后的字串   
   var theRequest = new Object();   
   if (url.indexOf("?") != -1) {   
      var str = url.substr(1);   
      strs = str.split("&");   
      for(var i = 0; i < strs.length; i ++) {   
         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
      }   
   }   
   return theRequest;   
} 